#### R Script File for Your Typical Criminal: Why White Americans Hate Voter Fraud
#### Adriano Udani, David Kimball, and Anita Manion
#### January 24, 2024

# If you do not have following packages, please use install.packages() command first to download to your computer
library(tidyverse)
library(survey)
library(readstata13)
library(MASS)
library(dotwhisker)
library(broom)
library(stargazer)
library(srvyr)
library(gridExtra)
library(grid)
library(ggpubr)

### CES Data, Independent Variables, Dependent Variables, and Data Subsets

# Data
cces17 <- read.dta13("cces17umsl.dta")
cces18 <- read.dta13("cces18umsl.dta")
cces20 <- read.dta13("ces20umsl.dta")

# Independent Variables
cces17$pid7.numb <- as.numeric(cces17$pid7)
cces17$pid7catwns <- ifelse(cces17$pid7.numb == 1, 1,
                          ifelse(cces17$pid7.numb == 2, 1,
                                 ifelse(cces17$pid7.numb == 3, 1,
                                        ifelse(cces17$pid7.numb == 5, 3,
                                               ifelse(cces17$pid7.numb == 6, 3,
                                                      ifelse(cces17$pid7.numb == 7, 3, 2))))))



cces18$pid7.numb <- as.numeric(cces18$pid7)
cces18$pid7catwns <- ifelse(cces18$pid7.numb == 1, 1,
                            ifelse(cces18$pid7.numb == 2, 1,
                                   ifelse(cces18$pid7.numb == 3, 1,
                                          ifelse(cces18$pid7.numb == 5, 3,
                                                 ifelse(cces18$pid7.numb == 6, 3,
                                                        ifelse(cces18$pid7.numb == 7, 3, 2))))))

cces20$pid7catwns <- ifelse(cces20$pid7 == 1, 1,
                            ifelse(cces20$pid7 == 2, 1,
                                   ifelse(cces20$pid7 == 3, 1,
                                          ifelse(cces20$pid7 == 5, 3,
                                                 ifelse(cces20$pid7 == 6, 3,
                                                        ifelse(cces20$pid7 == 7, 3, 2))))))

cces17$iUMS438x <- cces17$UMS438x/100 
cces17$iUMS438 <- cces17$UMS438/100 
cces17$iUMS437 <- cces17$UMS437/100 
cces17$ipid7catwns <- (cces17$pid7catwns-1)/2
cces17$newsintwdk <- ifelse(cces17$newsint == "Most of the time", 4,
                            ifelse(cces17$newsint == "Some of the time", 3,
                                   ifelse(cces17$newsint == "Only now and then", 2, 1)))
cces17$inewsintwdk <- (cces17$newsintwdk-1)/3  
cces17$ieduc <- (as.numeric(cces17$educ)-1)/5
cces17$age <- (2017-cces17$birthyr)
cces17$iage <- (cces17$age - 18)/70
cces17$gender2 <- cces17$gender

cces18$ipid7catwns <- (cces18$pid7catwns-1)/2
cces18$newsintwdk <- ifelse(cces18$newsint == "Most of the time", 4,
                            ifelse(cces18$newsint == "Some of the time", 3,
                                   ifelse(cces18$newsint == "Only now and then", 2, 1)))
cces18$inewsintwdk <- (cces18$newsintwdk-1)/3  
cces18$ieduc <- (as.numeric(cces18$educ)-1)/5
cces18$age <- (2018-cces18$birthyr)
cces18$iage <- (cces18$age - 18)/69

cces20$ipid7catwns <- (cces20$pid7catwns-1)/2
cces20$newsintwdk <- ifelse(cces20$newsint == "Most of the time", 4,
                            ifelse(cces20$newsint == "Some of the time", 3,
                                   ifelse(cces20$newsint == "Only now and then", 2, 1)))
cces20$inewsintwdk <- (cces20$newsintwdk-1)/3  
cces20$ieduc <- (as.numeric(cces20$educ)-1)/5
cces20$age <- (2019-cces20$birthyr)
cces20$iage <- (cces20$age - 18)/73

# Dependent Variables #
cces17$UMS414rev.number <- ifelse(cces17$UMS414 == "Support strongly", 4,
                                  ifelse(cces17$UMS414 == "Support somewhat",3,
                                         ifelse(cces17$UMS414 == "Oppose somewhat",2,1)))

cces17$UMS416rev.number <- ifelse(cces17$UMS416 == "Support strongly", 4,
                                  ifelse(cces17$UMS416 == "Support somewhat",3,
                                         ifelse(cces17$UMS416 == "Oppose somewhat",2,1)))

cces17$UMS439_1rc.number <- ifelse(cces17$UMS439_1 == "not selected",0,1)
cces17$UMS440_1rc.number <- ifelse(cces17$UMS440_1 == "not selected",0,1)
cces17$UMS441_1rc.number <- ifelse(cces17$UMS441_1rc == "not selected",0,1)

cces17.white$UMS439_1rc.number <- ifelse(cces17.white$UMS439_1rc == "Not Selected",0,1)
cces17.white$UMS440_1rc.number <- ifelse(cces17.white$UMS440_1rc == "Not Selected",0,1)
cces17.white$UMS441_1rc.number <- ifelse(cces17.white$UMS441_1rc == "Not Selected",0,1)

cces18$UMS336rev.number <- ifelse(cces18$UMS336 == "Support strongly", 4,
                                  ifelse(cces18$UMS336 == "Support somewhat",3,
                                         ifelse(cces18$UMS336 == "Oppose somewhat",2,1)))

cces18$UMS337.number <- ifelse(cces18$UMS337 == "Support strongly", 4,
                               ifelse(cces18$UMS337 == "Support somewhat",3,
                                      ifelse(cces18$UMS337 == "Oppose somewhat",2,1)))

cces18$STL430x_1rc.number <- ifelse(cces18$STL430x_1 == "not selected",0,1)
cces18$STL431x_1rc.number <- ifelse(cces18$STL431x_1 == "not selected",0,1)
cces18$STL432x_1rc.number <- ifelse(cces18$STL432x_1 == "not selected",0,1)

cces20$UMS342rev.number <- ifelse(cces20$UMS342 == 1, 5,
                                  ifelse(cces20$UMS342 == 2, 4,
                                         ifelse(cces20$UMS342 == 3, 3,
                                                ifelse(cces20$UMS342 == 4, 2,1))))

# Data Subsets #
cces17.white <- subset(cces17, subset = (race == "White"))
cces17.white.dem <- subset(cces17, subset = (race == "White" & pid7catwns == 1))
cces17.white.ind <- subset(cces17, subset = (race == "White" & pid7catwns == 2))
cces17.white.rep <- subset(cces17, subset = (race == "White" & pid7catwns == 3))

cces18.white <- subset(cces18, subset = (race == "White"))
cces18.white.dem <- subset(cces18, subset = (race == "White" & pid7catwns == 1))
cces18.white.ind <- subset(cces18, subset = (race == "White" & pid7catwns == 2))
cces18.white.rep <- subset(cces18, subset = (race == "White" & pid7catwns == 3))

cces20.white <- subset(cces20, subset = (race == 1))
cces20.white.dem <- subset(cces20, subset = (race == 1 & pid7catwns == 1))
cces20.white.ind <- subset(cces20, subset = (race == 1 & pid7catwns == 2))
cces20.white.rep <- subset(cces20, subset = (race == 1 & pid7catwns == 3))

###################### Section A, Supplemental Materials ######################

## Fraud ### 
cces17.white.white <- lm(fraudscale ~ as.numeric(iUMS438x) + as.numeric(ipid7catwns) + 
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                       data = cces17.white, weights = weights_UMS)

cces17.white.bl <- lm(fraudscale ~ as.numeric(iUMS438) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces17.white, weights = weights_UMS)

cces17.white.imm <- lm(fraudscale ~ as.numeric(iUMS437) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces17.white, weights = weights_UMS)

cces18.white.wh <- lm(fraudscale ~ as.numeric(iUMS330) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white, weights = teamweight)

cces18.white.bl <- lm(fraudscale ~ as.numeric(iUMS331) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white, weights = teamweight)

cces18.white.lat <- lm(fraudscale ~ as.numeric(iUMS332) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                       data = cces18.white, weights = teamweight)

cces18.white.ar <- lm(fraudscale ~ as.numeric(iUMS333) + as.numeric(ipid7catwns) + 
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                       data = cces18.white, weights = teamweight)

cces20.white.wh <- lm(fraudscale ~ as.numeric(iUMS355_1) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces20.white, weights = teamweight)

cces20.white.bl <- lm(fraudscale ~ as.numeric(iUMS356_1) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces20.white, weights = teamweight)

cces20.white.lat <- lm(fraudscale ~ as.numeric(iUMS357_1) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces20.white, weights = teamweight)

ces2017model <- dwplot(list(cces17.white.white, cces17.white.bl, cces17.white.imm),  dot_args = list(aes(shape = model), size = 3), 
       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2017 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Models",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Models",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Models"), colour = guide_legend("Models"))

stargazer(cces17.white.white, cces17.white.bl, cces17.white.imm, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black", 
                                             "Perceived % Immigrant",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("CES 2017"), align=TRUE,
          column.separate = c(2),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are OLS regression coefficients (standard errors in parentheses).", "Positive coefficients indicate voter fraud occurs more frequently.", "Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1). "),
          out = "ces17fr.htm")

ces2018model <- dwplot(list(cces18.white.wh, cces18.white.lat, cces18.white.bl, cces18.white.ar), dot_args = list(aes(shape = model), size = 3), 
       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(iUMS330)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2018 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
    scale_shape_discrete(name  ="Model",
                         breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                         labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
    scale_colour_grey(start = .4, end = .8,
                      name = "Model",
                      breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                      labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
    guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

stargazer(cces18.white.wh, cces18.white.lat, cces18.white.bl, cces18.white.ar, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Latino",
                                             "Perceived % Black",
                                             "Perceived % Arab",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("CES 2018"), align=TRUE,
          column.separate = c(3),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are OLS regression coefficients (standard errors in parentheses).", "Positive coefficients indicate voter fraud occurs more frequently.", "Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces18fr.htm")

stargazer(cces20.white.wh, cces20.white.bl, cces20.white.lat, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black", 
                                             "Perceived % Latino",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("CES 2020"), align=TRUE,
          column.separate = c(2),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are OLS regression coefficients (standard errors in parentheses).", "Positive coefficients indicate voter fraud occurs more frequently. Non-discrete", "variables are rescaled from 0 to 1. Party ID ranges from Democrat (0),", "Independent (.5), to Republican (1). 2020 CES voter fraud questions are meaured", "differently in two ways. Voter fraud is asked in context of respondent's state. Respondents", "are asked to estimate proportion of illegal ballots by racial group, such that", "percentages total 100%. The 2020 CES results reflect the effects of each", "typification mdeasure in separate models using the same controls."),
          out = "ces20fr.htm")


ces2020model <- dwplot(list(cces20.white.wh, cces20.white.bl, cces20.white.lat), dot_args = list(aes(shape = model), size = 3), 
       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2020 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.typ <- ggarrange(ces2017model, ces2018model, ces2020model, ncol=2, nrow=2, common.legend = FALSE, legend="bottom")

##### Figure 3 in Main text 
pdf(file = "summary_cesfraud.pdf", height = 8, width = 10)
annotate_figure(combinedplot.typ, top = text_grob(" ", 
                                              color = "black", face = "bold", size = 18),
                bottom = text_grob("Source: 2017, 2018, 2020 CES Team Modules.\nNote: OLS regression coefficients. Positive coefficients indicate voter fraud occurs more frequently. Non-discrete variables are rescaled from 0 to 1. Party ID ranges \nfrom Democrat (0), Independent (.5), to Republican (1). 2020 CES voter fraud questions are meaured differently in two ways. Voter fraud is asked in context of respondent's state. Respondents \nare asked to estimate proportion of illegal ballots by racial group, such that percentages total 100%. The 2020 CES results reflect the effects of each typification mdeasure in separate models \nusing the same controls.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

## Restrictions.Photo ID 
cces17.white.photoid.wh <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438x) + as.numeric(ipid7catwns) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                 data = cces17.white, weights = weights_UMS, Hess = TRUE)

cces17.white.photoid.imm <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS437) + as.numeric(ipid7catwns) + 
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                       data = cces17.white, weights = weights_UMS, Hess = TRUE)

cces17.white.photoid.bl <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438) + as.numeric(ipid7catwns) + 
                             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                           data = cces17.white, weights = weights_UMS, Hess = TRUE)

cces18.white.photoid.wh <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS330) + as.numeric(ipid7catwns) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white, weights = teamweight, Hess = TRUE)

cces18.white.photoid.bl <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS331) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white, weights = teamweight, Hess = TRUE)

cces18.white.photoid.lat <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS332) + as.numeric(ipid7catwns) + 
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                       data = cces18.white, weights = teamweight, Hess = TRUE)

cces18.white.photoid.ar <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS333) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white, weights = teamweight, Hess = TRUE)

cces20.white.photoid.wh <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS355_1) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces20.white, weights = teamweight, Hess = TRUE)

cces20.white.photoid.bl <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS356_1) + as.numeric(ipid7catwns) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                      data = cces20.white, weights = teamweight, Hess = TRUE)

cces20.white.photoid.lat <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS357_1) + as.numeric(ipid7catwns) + 
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                       data = cces20.white, weights = teamweight, Hess = TRUE)

ces2017model.photoid <- dwplot(list(cces17.white.photoid.wh, cces17.white.photoid.imm, cces17.white.photoid.bl), dot_args = list(aes(shape = model), size = 3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2017 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018model.photoid <- dwplot(list(cces18.white.photoid.wh, cces18.white.photoid.lat, cces18.white.photoid.bl, cces18.white.photoid.ar), dot_args = list(aes(shape = model), size = 3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(iUMS330)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2018 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                       labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                    labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2020model.photoid <- dwplot(list(cces20.white.photoid.wh, cces20.white.photoid.bl, cces20.white.photoid.lat), dot_args = list(aes(shape = model), size = 3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2020 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

stargazer(cces17.white.photoid.wh, cces17.white.photoid.imm, cces17.white.photoid.bl, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("CES 2017"), align=TRUE,
          column.separate = c(2),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces17photoid.htm")

stargazer(r4, r5, r6, r7, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Latino",
                                             "Perceived % Black",
                                             "Perceived % Arab",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("CES 2018"), align=TRUE,
          column.separate = c(3),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces18photoid.htm")

stargazer(cces20.white.photoid.wh, cces20.white.photoid.bl, cces20.white.photoid.lat, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black", 
                                             "Perceived % Latino",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("CES 2020"), align=TRUE,
          column.separate = c(2),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1.", "Party ID ranges from Democrat (0), Independent (.5), to Republican (1). 2020 CES voter fraud", "questions are meaured differently in two ways.", "Voter fraud is asked in context of respondent's state. Respondents", "are asked to estimate proportion of illegal ballots by racial group, such that", "percentages total 100%. The 2020 CES results reflect the effects of each", "typification mdeasure in separate models using the same controls."),
          out = "ces20photoid.htm")

r1 <- cces17.white.photoid.wh
r2 <- cces17.white.photoid.imm
r3 <- cces17.white.photoid.bl
r4 <- cces18.white.photoid.wh
r5 <- cces18.white.photoid.lat
r6 <- cces18.white.photoid.bl
r7 <- cces18.white.photoid.ar
r8 <- cces20.white.photoid.wh
r9 <- cces20.white.photoid.bl
r10 <- cces20.white.photoid.lat

combinedplot.photoid <- ggarrange(ces2017model.photoid, ces2018model.photoid, ces2020model.photoid, ncol=2, nrow=2, common.legend = FALSE, legend="bottom")

#### Figure 4 in Main Text 
pdf(file = "summary_cestyp_photoid.pdf", height = 8, width = 10)
annotate_figure(combinedplot.photoid, top = text_grob(" ", 
                                                  color = "black", face = "bold", size = 18),
                bottom = text_grob("Source: 2017, 2018, 2020 CES Team Modules.\nNote: Cell entries are ordinal regression coefficients. Positive coefficients indicate stronger support. 2020 CES voter fraud \nquestions are meaured differently in two ways. Voter fraud is asked in context of respondent's state. Respondents are asked to estimate proportion of illegal ballots by racial group, such that \npercentages total 100%. The 2020 CES results reflect the effects of each typification mdeasure in separate models using the same controls.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

## Restrictions.Felon Enfranchisement
cces17.white.felon.wh <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438x) + as.numeric(ipid7catwns) + 
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces17.white, weights = weights_UMS, Hess = TRUE)

cces17.white.felon.imm <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS437) + as.numeric(ipid7catwns) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                 data = cces17.white, weights = weights_UMS, Hess = TRUE)

cces17.white.felon.bl <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438) + as.numeric(ipid7catwns) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces17.white, weights = weights_UMS, Hess = TRUE)

cces18.white.felon.wh <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS330) + as.numeric(ipid7catwns) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white, weights = teamweight, Hess = TRUE)

cces18.white.felon.bl <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS331) + as.numeric(ipid7catwns) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white, weights = teamweight, Hess = TRUE)

cces18.white.felon.lat <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS332) + as.numeric(ipid7catwns) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                 data = cces18.white, weights = teamweight, Hess = TRUE)

cces18.white.felon.ar <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS333) + as.numeric(ipid7catwns) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white, weights = teamweight, Hess = TRUE)


ces2017model.felon <- dwplot(list(cces17.white.felon.wh, cces17.white.felon.imm, cces17.white.felon.bl), dot_args = list(aes(shape = model), size = 3), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2017 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018model.felon <- dwplot(list(cces18.white.felon.wh, cces18.white.felon.lat, cces18.white.felon.bl, cces18.white.felon.ar), dot_args = list(aes(shape = model), size = 3), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(iUMS330)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("2018 CES") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                       labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                    labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.felon <- ggarrange(ces2017model.felon, ces2018model.felon, ncol=2, nrow=1, common.legend = FALSE, legend="bottom")

#### Figure 5 in Main Text
pdf(file = "summary_cestyp_felon.pdf", height = 8, width = 10)
annotate_figure(combinedplot.felon, top = text_grob(" ", 
                                                      color = "black", face = "bold", size = 18),
                bottom = text_grob("Source: 2017 and 2018 CES Team Modules.\nNote: Ordinal regression coefficients provided. Positive coefficients indicate stronger opposition. Party ID ranges from Democrat (0), Independent (.5), to Republican (1).",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

o1 <- cces17.white.felon.wh
o2 <- cces17.white.felon.imm
o3 <- cces17.white.felon.bl
o4 <- cces18.white.felon.wh
o5 <- cces18.white.felon.lat
o6 <- cces18.white.felon.bl
o7 <- cces18.white.felon.ar

stargazer(o1, o2, o3, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant",
                                             "Perceived % Black",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c(" "),
          column.labels = c("CES 2017"), align=TRUE,
          column.separate = c(3),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger opposition. Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces17felon.htm")

stargazer(o4, o5, o6, o7, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Latino",
                                             "Perceived % Black",
                                             "Perceived % Arab",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c(" "),
          column.labels = c("CES 2018"), align=TRUE,
          column.separate = c(3),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger opposition. Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces18felon.htm")
  
## Punishment
cces17.white.punish.more.wh <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438x) + as.numeric(ipid7catwns) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))
cces17.white.punish.more.imm <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS437) + as.numeric(ipid7catwns) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                 data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))
cces17.white.punish.more.bl <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438) + as.numeric(ipid7catwns) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))

cces17.white.punish.some.wh <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438x) + as.numeric(ipid7catwns) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))
cces17.white.punish.some.imm <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS437) + as.numeric(ipid7catwns) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))
cces17.white.punish.some.bl <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))

cces17.white.punish.noncit.wh <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438x) + as.numeric(ipid7catwns) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                      data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))
cces17.white.punish.noncit.imm <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS437) + as.numeric(ipid7catwns) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                      data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))
cces17.white.punish.noncit.bl <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438) + as.numeric(ipid7catwns) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces17.white, weights = weights_UMS, family=binomial(link="logit"))

ces2017model.punish.more <- dwplot(list(cces17.white.punish.more.wh, cces17.white.punish.more.imm, cces17.white.punish.more.bl), dot_args = list(aes(shape = model), size = 3), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("More than Once") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017model.punish.some <- dwplot(list(cces17.white.punish.some.wh, cces17.white.punish.some.imm, cces17.white.punish.some.bl), dot_args = list(aes(shape = model), size = 3), 
                                   style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Voting As Someone Else") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017model.punish.nonc <- dwplot(list(cces17.white.punish.noncit.wh, cces17.white.punish.noncit.imm, cces17.white.punish.noncit.bl), dot_args = list(aes(shape = model), size = 3), 
                                   style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Noncitizen Voting") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Model 1", "Model 2", "Model 3")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Model 1", "Model 2", "Model 3")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.punish17 <- ggarrange(ces2017model.punish.more, ces2017model.punish.some, ces2017model.punish.nonc, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_cestyp_punish17.pdf", height = 6, width = 8)
annotate_figure(combinedplot.punish17, top = text_grob("Typification Effects on Public Support for\nAwarding Prison Time for Voter Fraud\n", 
                                                    color = "black", face = "bold", size = 18),
                bottom = text_grob("Source: 2017 and 2018 CES Team Modules.\nNote: Ordinal regression coefficients provided. Positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1. \nParty ID ranges from Democrat (0), Independent (.5), to Republican (1).",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

cces18.white.punish.more.wh <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS330) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.more.bl <- glm(as.factor(STL430x_1rc.number) ~as.numeric(iUMS331) + as.numeric(ipid7catwns) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.more.lat <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS332) + as.numeric(ipid7catwns) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                 data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.more.ar <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + as.numeric(ipid7catwns) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.some.wh <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS330) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.some.bl <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS331) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.some.lat <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS332) + as.numeric(ipid7catwns) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.some.ar <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.noncit.wh <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS330) + as.numeric(ipid7catwns) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.noncit.bl <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS331) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.noncit.lat <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS332) + as.numeric(ipid7catwns) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white, weights = teamweight, family=binomial(link="logit"))

cces18.white.punish.noncit.ar <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS333) + as.numeric(ipid7catwns) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white, weights = teamweight, family=binomial(link="logit"))

ces2018model.punish.more <- dwplot(list(cces18.white.punish.more.wh, cces18.white.punish.more.lat, cces18.white.punish.more.bl, cces18.white.punish.more.ar), dot_args = list(aes(shape = model), size = 3), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(iUMS330)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("More Than Once") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                       labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                    labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018model.punish.some <- dwplot(list(cces18.white.punish.some.wh, cces18.white.punish.some.lat, cces18.white.punish.some.bl, cces18.white.punish.some.ar), dot_args = list(aes(shape = model), size = 3), 
                                   style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(iUMS330)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Voting As Someone Else") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                       labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                    labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018model.punish.nonc <- dwplot(list(cces18.white.punish.noncit.wh, cces18.white.punish.noncit.lat, cces18.white.punish.noncit.bl, cces18.white.punish.noncit.ar), dot_args = list(aes(shape = model), size = 3), 
                                   style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1)) %>%
  relabel_predictors('as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(iUMS330)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Party ID",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Noncitizen Voting") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                       labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3", "Model 4"),
                    labels = c("Model 1", "Model 2", "Model 3", "Model 4")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))


combinedplot.punish17 <- ggarrange(ces2017model.punish.more, ces2017model.punish.some, ces2017model.punish.nonc, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

summary_cestyp_punish17.pdf <- annotate_figure(combinedplot.punish17, top = text_grob("2017 CES", 
                                                                                      color = "black", face = "bold", size = 12))

combinedplot.punish18 <- ggarrange(ces2018model.punish.more, ces2018model.punish.some, ces2018model.punish.nonc, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

summary_cestyp_punish18.pdf <- annotate_figure(combinedplot.punish18, top = text_grob("2018 CES", 
                                                                                      color = "black", face = "bold", size = 12))

combinedplot.punish1718 <- ggarrange(summary_cestyp_punish17.pdf, summary_cestyp_punish18.pdf, ncol=1, nrow=2, common.legend = FALSE, legend="bottom")

#### Figure 6 in Main Text
pdf(file = "summary_cestyp_punish1718.pdf", height = 10, width = 10)
annotate_figure(combinedplot.punish1718, top = text_grob(" ", 
                                                       color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017 and 2018 CES Team Modules.\nNote: Ordinal regression coefficients provided. Positive coefficients indicate stronger support.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

stargazer(cces17.white.punish.noncit.imm, cces17.white.punish.noncit.bl, style = "apsr",
          title = "Table XX. Predictors of Public Support for Felon Enfranchisement, White Respondents",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Republican Party affiliation",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("Noncitizen Voting"), align=TRUE,
          column.separate = c(2),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "tab16.htm")

n1 <- cces17.white.punish.more.wh
n2 <- cces17.white.punish.more.imm
n3 <- cces17.white.punish.more.bl
n4 <- cces17.white.punish.some.wh
n5 <- cces17.white.punish.some.imm
n6 <- cces17.white.punish.some.bl
n7 <- cces17.white.punish.noncit.wh
n8 <- cces17.white.punish.noncit.imm
n9 <- cces17.white.punish.noncit.bl

stargazer(n1, n2, n3, n4, n5, n6, n7, n8, n9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("More Than Once", "Someone Else", "Noncitizen Voting"), align=TRUE,
          column.separate = c(3,3,3),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1.", "Party ID ranges from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces17punish.htm")

m1 <- cces18.white.punish.more.wh
m2 <- cces18.white.punish.more.lat 
m3 <- cces18.white.punish.more.bl 
m4 <- cces18.white.punish.more.ar 
m5 <- cces18.white.punish.some.wh 
m6 <- cces18.white.punish.some.lat 
m7 <- cces18.white.punish.some.bl
m8 <- cces18.white.punish.some.ar
m9 <- cces18.white.punish.noncit.wh
m10 <- cces18.white.punish.noncit.lat
m11 <- cces18.white.punish.noncit.bl
m12 <- cces18.white.punish.noncit.ar

stargazer(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Latino",
                                             "Perceived % Black",
                                             "Perceived % Arab",
                                             "Party ID",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          dep.var.labels = c("", "", ""),
          column.labels = c("More Than Once", "Someone Else", "Noncitizen Voting"), align=TRUE,
          column.separate = c(4,4,4),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1.", "Party ID ranges from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces18punish.htm")

#### Figure 2 in Main Text
dat.ces17.white <- data.frame(Group= factor(rep(c("Immigrant", "Black", "White"))), 
                        rating = c(cces17.white$UMS437, cces17.white$UMS438, cces17.white$UMS438x))

dat.ces18.white <- data.frame(Group= factor(rep(c("Latino", "Black", "Arab", "White"))), 
                              rating = c(cces18.white$UMS332, cces17.white$UMS331, cces17.white$UMS333, cces17.white$UMS330))

dat.ces20.white <- data.frame(Group= factor(rep(c("Latino", "Black", "White"))), 
                              rating = c(cces20.white$UMS357_1, cces20.white$UMS356_1, cces20.white$UMS355_1))

typwhites17.density <- ggplot(dat.ces17.white, aes(x=rating, fill=Group)) + geom_density(alpha=0.5) +
  ggtitle("2017 CCES") + xlab("Group as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
        axis.text.y = element_text(size = 16),
        axis.text.x = element_text(size = 16),
        axis.title.x = element_text(size = 16, face = "bold")) +
  theme(legend.position = c(.83, .80),
        legend.background = element_rect(colour=NULL, fill = "grey93"),
        legend.text = element_text(size = 12),
        legend.key.size = unit(1, "cm"),
        legend.title = element_text(face = "bold", size = 11),
        legend.title.align = .5) +
  scale_y_continuous(limits=c(0, 0.030))

typwhites18.density <- ggplot(dat.ces18.white, aes(x=rating, fill=Group)) + geom_density(alpha=0.5) +
  ggtitle("2018 CCES") + xlab("Group as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
        axis.text.y = element_text(size = 16),
        axis.text.x = element_text(size = 16),
        axis.title.x = element_text(size = 16, face = "bold")) +
  theme(legend.position = c(.83, .80),
        legend.background = element_rect(colour=NULL, fill = "grey93"),
        legend.text = element_text(size = 12),
        legend.key.size = unit(1, "cm"),
        legend.title = element_text(face = "bold", size = 11),
        legend.title.align = .5) +
  scale_y_continuous(limits=c(0, 0.030))

typwhites20.density <- ggplot(dat.ces20.white, aes(x=rating, fill=Group)) + geom_density(alpha=0.5) +
  ggtitle("2020 CCES") + xlab("Group as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
        axis.text.y = element_text(size = 16),
        axis.text.x = element_text(size = 16),
        axis.title.x = element_text(size = 16, face = "bold")) +
  theme(legend.position = c(.83, .80),
        legend.background = element_rect(colour=NULL, fill = "grey93"),
        legend.text = element_text(size = 12),
        legend.key.size = unit(1, "cm"),
        legend.title = element_text(face = "bold", size = 11),
        legend.title.align = .5) +
  scale_y_continuous(limits=c(0, 0.031))

combinedplot.typwhites <- ggarrange(typwhites17.density, typwhites18.density, typwhites20.density, ncol=2, nrow=2, common.legend = FALSE, legend="bottom")

pdf(file = "summary_typwhitesdensity.pdf", height = 16, width = 10)
annotate_figure(combinedplot.typwhites, top = text_grob(" ", 
                                                          color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017, 2018, and 2020 CES Team Modules.\nNote: Scales are 0 - 100. Larger number indicate larger percentage of illegal ballots casted.\n 2020 CES module asked resopndents to give percentages that total 100%.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

dat2 <- data.frame(party= factor(cces17.white$pid7catwns),
                   immrating = cces17.white$UMS437, 
                   blrating = cces17.white$UMS438, 
                   whrating = cces17.white$UMS438x)

dat3 <- data.frame(party= factor(cces18.white$pid7catwns),
                   latrating = cces18.white$UMS332, 
                   blrating = cces18.white$UMS331,
                   arrating = cces18.white$UMS333,
                   whrating = cces18.white$UMS330)

ggplot.imm <- ggplot(dat2,aes(x=immrating, fill=party)) + geom_density(alpha=0.75) +
  ggtitle("Immigrant Typification") + xlab("Immigrants as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(.79, .75),
        legend.background = element_rect(colour=NULL, fill = "grey93"),
        legend.text = element_text(size = 8),
        legend.key.size = unit(.5, "cm"),
        legend.title = element_text(face = "bold", size = 11),
        legend.title.align = .5) +
  scale_y_continuous(limits=c(0, 0.03)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000")) 
ggplot.bl <- ggplot(dat2,aes(x=blrating, fill=party)) + geom_density(alpha=0.75) +
  ggtitle("Black Typification") + xlab("Blacks as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="none") +
  scale_y_continuous(limits=c(0, 0.03)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000"))
ggplot.wh <- ggplot(dat2,aes(x=whrating, fill=party)) + geom_density(alpha=0.75) + 
  ggtitle("White Typification") + xlab("Whites as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="none") +
  scale_y_continuous(limits=c(0, 0.03)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000"))

pdf(file = "typbypartyces17.pdf", height = 8, width = 10)
grid.arrange(ggplot.imm, ggplot.bl, ggplot.wh, nrow=2, 
             top = textGrob("2017 CES", gp=gpar(fontsize=18)))
dev.off()

ggplot.white18 <- dat3 %>%
  filter(party != "NA") %>%
  ggplot(aes(x=whrating, fill=party)) + geom_density(alpha=0.75) +
  ggtitle("White Typification") + xlab("Whites as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(.69, .75),
        legend.background = element_rect(colour=NULL, fill = "white"),
        legend.text = element_text(size = 8),
        legend.key.size = unit(.5, "cm"),
        legend.title = element_text(face = "bold", size = 11),
        legend.title.align = .5) +
  scale_y_continuous(limits=c(0, 0.06)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000")) 
ggplot.bl18 <- dat3 %>%
  filter(party != "NA") %>%
  ggplot(aes(x=blrating, fill=party)) + geom_density(alpha=0.75) +
  ggtitle("Black Typification") + xlab("Blacks as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="none") +
  scale_y_continuous(limits=c(0, 0.06)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000"))
ggplot.lat18 <- dat3 %>%
  filter(party != "NA") %>%
  ggplot(aes(x=latrating, fill=party)) + geom_density(alpha=0.75) + 
  ggtitle("Latino Typification") + xlab("Latinos as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="none") +
  scale_y_continuous(limits=c(0, 0.06)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000"))
ggplot.arab18 <- dat3 %>%
  filter(party != "NA") %>%
  ggplot(aes(x=arrating, fill=party)) + geom_density(alpha=0.75) + 
  ggtitle("Arab Typification") + xlab("Arabs as % of Illegal Ballots") + ylab("") +
  theme_bw() +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position="none") +
  scale_y_continuous(limits=c(0, 0.06)) +
  scale_fill_manual(values=c("#FFFFFF", "#CCCCCC", "#330000"))

pdf(file = "typbypartyces18.pdf", height = 8, width = 10)
grid.arrange(ggplot.white18, ggplot.bl18, ggplot.lat18, ggplot.arab18, ncol=2, nrow=2, 
             top = textGrob("2018 CES", gp=gpar(fontsize=18)))
dev.off()

typ.comparepop <- data.frame(race = as.factor(c("Whites","Whites", "Blacks", "Blacks",
                                                "Immigrants", "Immigrants")),
                             survey = as.factor(rep(c("CCES Typification Estimates (Mean) ","2017 ACS 5-Year Population Estimates"))),
                             estimate = as.numeric(c(46,73.3,33,12.6,37,13.5)))

pdf(file = "typacs.pdf", height = 7, width = 10)
ggplot(typ.comparepop, aes(x=race, fill=survey)) + 
  geom_bar(aes(y=estimate), stat="identity", position=position_dodge()) +
  ggtitle("Typification Estimates Compared to Proportion of U.S. Population\n") + xlab("\nRace") + ylab("People (%)\n") +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
        axis.text.y = element_text(size = 16),
        axis.text.x = element_text(size = 16),
        axis.title.x = element_text(size = 16, face = "bold"),
        axis.title.y = element_text(size = 16, face = "bold")) +
  theme(legend.position = c(.25, .85),
        legend.background = element_rect(colour=NULL, fill = "grey93"),
        legend.text = element_text(size = 12),
        legend.key.size = unit(.75, "cm"),
        legend.title = element_text(face = "bold", size = 11),
        legend.title.align = .5) +
  scale_y_continuous(limits=c(0, 80)) +
  guides(fill=guide_legend(title = " "))
dev.off()

###################### Sections B and E, Supplemental Materials ######################

## Fraud ### 
a1 <- lm(fraudscale ~ as.numeric(iUMS438x) + 
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                       data = cces17.white.dem, weights = weights_UMS)
a2 <- lm(fraudscale ~ as.numeric(iUMS438x) +
                             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                           data = cces17.white.ind, weights = weights_UMS)
a3 <- lm(fraudscale ~ as.numeric(iUMS438x) +
                             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                           data = cces17.white.rep, weights = weights_UMS)

a4 <- lm(fraudscale ~ as.numeric(iUMS437) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces17.white.dem, weights = weights_UMS)
a5 <- lm(fraudscale ~ as.numeric(iUMS437) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces17.white.ind, weights = weights_UMS)
a6 <- lm(fraudscale ~  as.numeric(iUMS437) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces17.white.rep, weights = weights_UMS)

a7 <- lm(fraudscale ~ as.numeric(iUMS438) + 
                             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                           data = cces17.white.dem, weights = weights_UMS)
a8 <- lm(fraudscale ~ as.numeric(iUMS438) + 
                             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                           data = cces17.white.ind, weights = weights_UMS)
a9 <- lm(fraudscale ~ as.numeric(iUMS438) + 
                             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                           data = cces17.white.rep, weights = weights_UMS)

stargazer(a1, a2, a3, a4, a5, a6, a7, a8, a9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant",
                                             "Perceived % Black",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are OLS regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate voter fraud occurs more frequently.", "Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces17party.htm")

ces2017.white <- dwplot(list(a1, a2, a3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1), 
                       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017.imm <- dwplot(list(a4, a5, a6), 
       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1), 
       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Immigrants") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017.black <- dwplot(list(a7, a8, a9), 
       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1), 
       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.2017 <- ggarrange(ces2017.white, ces2017.imm, ces2017.black, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2017.pdf", height = 6, width = 8)
annotate_figure(combinedplot.2017, top = text_grob("Voter Fraud Beliefs Among White U.S. Voters, 2017 CES", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nCell entries are OLS regression coefficients. Larger and positive coefficients indicate voter fraud occurs more frequently.\nNon-discrete variables are rescaled from 0 to 1. Party ID ranges from Democrat (0), Independent (.5), to Republican (1).",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

b1 <- lm(fraudscale ~ as.numeric(iUMS330) +
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white.dem, weights = teamweight)
b2 <- lm(fraudscale ~ as.numeric(iUMS330) +
                            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                          data = cces18.white.ind, weights = teamweight)
b3 <- lm(fraudscale ~ as.numeric(iUMS330) + 
                            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                          data = cces18.white.rep, weights = teamweight)

b4 <- lm(fraudscale ~ as.numeric(iUMS331) +  
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
         data = cces18.white.dem, weights = teamweight)
b5 <- lm(fraudscale ~ as.numeric(iUMS331) +  
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
         data = cces18.white.ind, weights = teamweight)
b6 <- lm(fraudscale ~ as.numeric(iUMS331) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
         data = cces18.white.rep, weights = teamweight)

b7 <- lm(fraudscale ~ as.numeric(iUMS332) +  
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                       data = cces18.white.dem, weights = teamweight)
b8 <- lm(fraudscale ~ as.numeric(iUMS332) +  
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                       data = cces18.white.ind, weights = teamweight)
b9 <- lm(fraudscale ~ as.numeric(iUMS332) +  
                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                       data = cces18.white.rep, weights = teamweight)

b10 <- lm(fraudscale ~ as.numeric(iUMS333) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white.dem, weights = teamweight)
b11 <- lm(fraudscale ~ as.numeric(iUMS333) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white.ind, weights = teamweight)
b12 <- lm(fraudscale ~ as.numeric(iUMS333) + 
                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                      data = cces18.white.rep, weights = teamweight)

stargazer(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Perceived % Arab",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are OLS regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate voter fraud occurs more frequently.", "Non-discrete variables are rescaled from 0 to 1. Party ID ranges", "from Democrat (0), Independent (.5), to Republican (1)."),
          out = "ces18party.htm")

ces2018.white <- dwplot(list(b1, b2, b3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018.black <- dwplot(list(b4, b5, b6), 
                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                        dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018.latino <- dwplot(list(b7, b8, b9), 
                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                        dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018.arab <- dwplot(list(b10, b11, b12), 
                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Arabs") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.2018 <- ggarrange(ces2018.white, ces2018.black, ces2018.latino, ces2018.arab, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2018.pdf", height = 6, width = 8)
annotate_figure(combinedplot.2018, top = text_grob("Voter Fraud Beliefs Among White U.S. Voters, 2018 CES", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nCell entries are OLS regression coefficients., Larger and positive coefficients indicatte stronger voter fraud beliefs. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

c1 <- lm(fraudscale ~ as.numeric(iUMS355_1) +  
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.dem, weights = teamweight)
c2 <- lm(fraudscale ~ as.numeric(iUMS355_1) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.ind, weights = teamweight)
c3 <- lm(fraudscale ~ as.numeric(iUMS355_1) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.rep, weights = teamweight)

c4 <- lm(fraudscale ~ as.numeric(iUMS356_1) +  
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.dem, weights = teamweight)
c5 <- lm(fraudscale ~ as.numeric(iUMS356_1) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.ind, weights = teamweight)
c6 <- lm(fraudscale ~ as.numeric(iUMS356_1) +  
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.rep, weights = teamweight)

c7 <- lm(fraudscale ~ as.numeric(iUMS357_1) +  
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.dem, weights = teamweight)
c8 <- lm(fraudscale ~ as.numeric(iUMS357_1) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.ind, weights = teamweight)
c9 <- lm(fraudscale ~ as.numeric(iUMS357_1) + 
           as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
         data = cces20.white.rep, weights = teamweight)

stargazer(c1, c2, c3, c4, c5, c6, c7, c8, c9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are OLS regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate voter fraud occurs more frequently. Non-discrete", "variables are rescaled from 0 to 1. Party ID ranges from Democrat (0),", "Independent (.5), to Republican (1). 2020 CES voter fraud questions are meaured", "differently in two ways. Voter fraud is asked in context of respondent's state. Respondents", "are asked to estimate proportion of illegal ballots by racial group, such that", "percentages total 100%. The 2020 CES results reflect the effects of each", "typification mdeasure in separate models using the same controls."),
          out = "ces20party.htm")

ces2020.white <- dwplot(list(c1, c2, c3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))


ces2020.black <- dwplot(list(c4, c5, c6), 
                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                        dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2020.latino <- dwplot(list(c7, c8, c9), 
                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                        dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.2020 <- ggarrange(ces2020.white, ces2020.black, ces2020.latino, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2020.pdf", height = 6, width = 8)
annotate_figure(combinedplot.2020, top = text_grob("Voter Fraud Beliefs Among White U.S. Voters, 2020 CES", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2020 CES Team Module.\nCell entries are OLS regression coefficients. Larger and positive coefficients indicatte stronger voter fraud beliefs. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

combinedplot.2017ann <- annotate_figure(combinedplot.2017, top = text_grob("2017 CES", 
                                                                           color = "black", face = "bold", size = 16),
                                        bottom = text_grob(" ",
                                                           hjust = 0, x = 0, face = "italic", size = 8))

combinedplot.2018ann <- annotate_figure(combinedplot.2018, top = text_grob("2018 CES", 
                                                                           color = "black", face = "bold", size = 16),
                                        bottom = text_grob(" ",
                                                           hjust = 0, x = 0, face = "italic", size = 8))

combinedplot.2020ann <- annotate_figure(combinedplot.2020, top = text_grob("2020 CES", 
                                                   color = "black", face = "bold", size = 16),
                                        bottom = text_grob(" ",
                                                           hjust = 0, x = 0, face = "italic", size = 8))

combinedplot.fraud <- ggarrange(combinedplot.2018ann, combinedplot.2020ann, ncol=1, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_vfraud1820.pdf", height = 10, width = 8)
annotate_figure(combinedplot.fraud, top = text_grob("\n", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: Cell entries are OLS regression coefficients (standard errors in parentheses). Larger and positive coefficients indicatte stronger voter fraud beliefs. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

## Restrictions.Photo ID 
d1 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438x) +
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                 data = cces17.white.dem, weights = weights_UMS, Hess = TRUE)
d2 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438x) +
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces17.white.ind, weights = weights_UMS, Hess = TRUE)
d3 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438x) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces17.white.rep, weights = weights_UMS, Hess = TRUE)
d4 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS437) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
           data = cces17.white.dem, weights = weights_UMS, Hess = TRUE)
d5 <- polr(as.factor(UMS414rev.number) ~as.numeric(iUMS437) +  
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
           data = cces17.white.ind, weights = weights_UMS, Hess = TRUE)
d6 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS437) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
           data = cces17.white.rep, weights = weights_UMS, Hess = TRUE)
d7 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438) + + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                data = cces17.white.dem, weights = weights_UMS, Hess = TRUE)
d8 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438) +  
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                data = cces17.white.ind, weights = weights_UMS, Hess = TRUE)
d9 <- polr(as.factor(UMS414rev.number) ~ as.numeric(iUMS438) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                data = cces17.white.rep, weights = weights_UMS, Hess = TRUE)

stargazer(d1, d2, d3, d4, d5, d6, d7, d8, d9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces17photoparty.htm")

ces2017photoid.white <- dwplot(list(d1, d2, d3), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                               dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017photoid.imm <- dwplot(list(d4, d5, d6), 
                            style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                            dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Immigrants") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017photoid.black <- dwplot(list(d7, d8, d9), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.2017photo <- ggarrange(ces2017photoid.white, ces2017photoid.imm, ces2017photoid.black, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2017photo.pdf", height = 6, width = 8)
annotate_figure(combinedplot.2017photo, top = text_grob("Photo ID Support Among White U.S. Voters, 2017 CES", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017 CES Team Module.\nCell entries are ordinal regression coefficients. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

e1 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS330) + 
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white.dem, weights = teamweight, Hess = TRUE)
e2 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS330) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.ind, weights = teamweight, Hess = TRUE)
e3 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS330) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.rep, weights = teamweight, Hess = TRUE)
e4 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS331) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces18.white.dem, weights = teamweight, Hess = TRUE)
e5 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS331) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces18.white.ind, weights = teamweight, Hess = TRUE)
e6 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS331) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces18.white.rep, weights = teamweight, Hess = TRUE)
e7 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS332) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                 data = cces18.white.dem, weights = teamweight, Hess = TRUE)
e8 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS332) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.ind, weights = teamweight, Hess = TRUE)
e9 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS332) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.rep, weights = teamweight, Hess = TRUE)
e10 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS333) +  
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                data = cces18.white.dem, weights = teamweight, Hess = TRUE)
e11 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS333) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.ind, weights = teamweight, Hess = TRUE)
e12 <- polr(as.factor(UMS336rev.number) ~ as.numeric(iUMS333) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.rep, weights = teamweight, Hess = TRUE)

stargazer(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Perceived % Arab",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces18photoparty.htm")

ces2018photo.white <- dwplot(list(e1, e2, e3), 
                       style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                       dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018photo.black <- dwplot(list(e4, e5, e6), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018photo.latino <- dwplot(list(e7, e8, e9), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018photo.arab <- dwplot(list(e10, e11, e12), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                            dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Arabs") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotphoto.2018 <- ggarrange(ces2018photo.white, ces2018photo.black, ces2018photo.latino, ces2018photo.arab, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2018photo.pdf", height = 6, width = 8)
annotate_figure(combinedplotphoto.2018, top = text_grob("Photo ID Support Among White U.S. Voters, 2018 CES", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nCell entries are ordinal regression coefficients. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

f1 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS355_1) +  
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                data = cces20.white.dem, weights = teamweight, Hess = TRUE)
f2 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS355_1) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces20.white.ind, weights = teamweight, Hess = TRUE)
f3 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS355_1) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces20.white.rep, weights = teamweight, Hess = TRUE)

f4 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS356_1) +  
                                  as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                data = cces20.white.dem, weights = teamweight, Hess = TRUE)
f5 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS356_1) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces20.white.ind, weights = teamweight, Hess = TRUE)
f6 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS356_1) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces20.white.rep, weights = teamweight, Hess = TRUE)

f7 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS357_1) + 
                                   as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                 data = cces20.white.dem, weights = teamweight, Hess = TRUE)
f8 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS357_1) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces20.white.ind, weights = teamweight, Hess = TRUE)
f9 <- polr(as.factor(UMS342rev.number) ~ as.numeric(iUMS357_1) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces20.white.rep, weights = teamweight, Hess = TRUE)

stargazer(f1, f2, f3, f4, f5, f6, f7, f8, f9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub", "Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1.", "Party ID ranges from Democrat (0), Independent (.5), to Republican (1). 2020 CES voter fraud", "questions are meaured differently in two ways. Voter fraud is asked in context of respondent's state.", "Respondents are asked to estimate proportion of illegal ballots by racial group, such that percentages total 100%.", "The 2020 CES results reflect the effects of each typification mdeasure in separate models using the same controls."),
          out = "ces20photoparty.htm")

ces2020photo.white <- dwplot(list(f1, f2, f3), 
                         style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                         dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2020photo.black <- dwplot(list(f4, f5, f6), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2020photo.latino <- dwplot(list(f7,f8,f9),
                             show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS356_1)' = "Black typification",
                     'as.numeric(iUMS357_1)' = "Latino typification",
                     'as.numeric(iUMS355_1)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)2' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))
  

combinedplotphoto.2020 <- ggarrange(ces2020photo.white, ces2020photo.black, ces2020photo.latino, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2020photo.pdf", height = 6, width = 8)
annotate_figure(combinedplotphoto.2020, top = text_grob("Photo ID Support Among White U.S. Voters, 2020 CES", 
                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2020 CES Team Module.\nOrdinal regression coefficients provided. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

## Punishment
g1 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438x) +
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
g2 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438x) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
g3 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438x) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))
g4 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
g5 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
g6 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))
g7 <- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
g8<- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438) +  
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
g9<- glm(as.factor(UMS439_1rc.number) ~ as.numeric(iUMS438) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))

stargazer(g1, g2, g3, g4, g5, g6, g7, g8, g9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep", "Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1, 1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces17punishmoreparty.htm")

ces2017punishmore.white <- dwplot(list(g1, g2, g3), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                               dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017punishmore.imm <- dwplot(list(g4, g5, g6), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Immigrants") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017punishmore.black <- dwplot(list(g7, g8, g9), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotpunishmore.2017 <- ggarrange(ces2017punishmore.white, ces2017punishmore.imm, ces2017punishmore.black, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2017punishmore.pdf", height = 6, width = 10)
annotate_figure(combinedplotpunishmore.2017, top = text_grob("White U.S. Voter Support for Awarding Prison Time for Voting More Than Once, 2017 CES", 
                                                        color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017 CES Team Module.\nLogit regression coefficients given. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

h1 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438x) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
h2 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438x) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
h3 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438x) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                    data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))
h4 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS437) +  
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
h5 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
h6 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS437) +  
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))
h7 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438) +  
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
h8 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
h9 <- glm(as.factor(UMS440_1rc.number) ~ as.numeric(iUMS438) +  
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                   data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))

ces2017punishsome.white <- dwplot(list(h1, h2, h3), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017punishsome.imm <- dwplot(list(h4, h5, h6), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Immigrants") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017punishsome.black <- dwplot(list(h7, h8, h9), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotpunishsome.2017 <- ggarrange(ces2017punishsome.white, ces2017punishsome.imm, ces2017punishsome.black, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2017punishsome.pdf", height = 6, width = 10)
annotate_figure(combinedplotpunishsome.2017, top = text_grob("White U.S. Voter Support for Awarding Prison Time for Voting As Someone Else, 2017 CES", 
                                                             color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017 CES Team Module.\nLogit regression coefficients given. Positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

stargazer(h1, h2, h3, h4, h5, h6, h7, h8, h9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep","Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Logit regression coefficients are given (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces17punishsomeoneparty.htm")

i1 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438x) + + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                      data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
i2 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438x) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                      data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
i3 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438x) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                      data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))
i4 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
i5 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
i6 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS437) +
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
          data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))
i7 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438) +  
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces17.white.dem, weights = weights_UMS, family=binomial(link="logit"))
i8 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces17.white.ind, weights = weights_UMS, family=binomial(link="logit"))
i9 <- glm(as.factor(UMS441_1rc.number) ~ as.numeric(iUMS438) +  
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender), 
                                     data = cces17.white.rep, weights = weights_UMS, family=binomial(link="logit"))

ces2017punishnoncitizen.white <- dwplot(list(i1, i2, i3), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017punishnoncitizen.imm <- dwplot(list(i4, i5, i6), 
                                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                        dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Immigrants") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017punishnoncitizen.black <- dwplot(list(i7, i8, i9), 
                                        style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                        dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotpunishnoncitizen.2017 <- ggarrange(ces2017punishnoncitizen.white, ces2017punishnoncitizen.imm, ces2017punishnoncitizen.black, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2017punishnoncitizen.pdf", height = 6, width = 10)
annotate_figure(combinedplotpunishnoncitizen.2017, top = text_grob("White U.S. Voter Support for Awarding Prison Time for Noncitizen Voting, 2017 CES", 
                                                             color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017 CES Team Module.\nLogit regression coefficients are given. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

stargazer(i1, i2, i3, i4, i5, i6, i7, i8, i9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep","Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces17punishnoncitizenparty.htm")

cces18.white.dem$STL430x_1rc.number <- ifelse(cces18.white.dem$STL430x_1rc == "Not Selected",0,1)
cces18.white.ind$STL430x_1rc.number <- ifelse(cces18.white.ind$STL430x_1rc == "Not Selected",0,1)
cces18.white.rep$STL430x_1rc.number <- ifelse(cces18.white.rep$STL430x_1rc == "Not Selected",0,1)

cces18.white.dem$STL431x_1rc.number <- ifelse(cces18.white.dem$STL431x_1rc == "Not Selected",0,1)
cces18.white.ind$STL431x_1rc.number <- ifelse(cces18.white.ind$STL431x_1rc == "Not Selected",0,1)
cces18.white.rep$STL431x_1rc.number <- ifelse(cces18.white.rep$STL431x_1rc == "Not Selected",0,1)

cces18.white.dem$STL432x_1rc.number <- ifelse(cces18.white.dem$STL432x_1rc == "Not Selected",0,1)
cces18.white.ind$STL432x_1rc.number <- ifelse(cces18.white.ind$STL432x_1rc == "Not Selected",0,1)
cces18.white.rep$STL432x_1rc.number <- ifelse(cces18.white.rep$STL432x_1rc == "Not Selected",0,1)

j1 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS330) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
j2 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS330) + 
                                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                       data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
j3 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS330) + 
                                         as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                       data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
j4 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
j5 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
j6 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
j7 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS332) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
j8 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS332) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
j9 <- glm(as.factor(STL430x_1rc.number) ~ as.numeric(iUMS332) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
j10 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
j11 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
j12 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))

stargazer(j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Perceived % Arab",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep","Dem", "Ind", "Rep", "Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces18punishmoreparty.htm")

ces2018punishmore.white <- dwplot(list(j1, j2, j3), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishmore.black <- dwplot(list(j4, j5, j6), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishmore.latino <- dwplot(list(j7, j8, j9), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishmore.arab <- dwplot(list(j10, j11, j12), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Arabs") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotpunishmore.2018 <- ggarrange(ces2018punishmore.white, ces2018punishmore.black, ces2018punishmore.latino, ces2018punishmore.arab, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2018punishmore.pdf", height = 6, width = 10)
annotate_figure(combinedplotpunishmore.2018, top = text_grob("White U.S. Voter Support for Awarding Prison Time for Voting More Than Once, 2018 CES", 
                                                                   color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nLogit regression coefficients are given. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

k1 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS330) +  
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
k2 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS330) +  
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
k3 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS330) +  
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
k4 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
k5 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
k6 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS331) +  
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
k7 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS332) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
k8 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS332) + 
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
k9<- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS332) +  
                                      as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                    data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
k10 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
k11 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
k12 <- glm(as.factor(STL431x_1rc.number) ~ as.numeric(iUMS333) + 
                                     as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                   data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))

stargazer(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Perceived % Arab",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep","Dem", "Ind", "Rep", "Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces18punishsomeoneparty.htm")

ces2018punishsome.white <- dwplot(list(k1, k2, k3), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishsome.black <- dwplot(list(k4, k5, k6), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishsome.latino <- dwplot(list(k7, k8, k9), 
                                   style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                   dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishsome.arab <- dwplot(list(k10, k11, k12), 
                                 style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                 dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Arabs") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotpunishsome.2018 <- ggarrange(ces2018punishsome.white, ces2018punishsome.black, ces2018punishsome.latino, ces2018punishsome.arab, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2018punishsome.pdf", height = 6, width = 10)
annotate_figure(combinedplotpunishsome.2018, top = text_grob("White U.S. Voter Support for Awarding Prison Time for Voting As Someone Else, 2018 CES", 
                                                             color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nLogit regression coefficients are given. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()


l1 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS330) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
l2 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS330) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
l3 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS330) +   
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
l4 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
l5 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS331) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
l6 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS331) +  
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
l7 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS332) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                      data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
l8 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS332) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                      data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
l9 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS332) + 
                                        as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                      data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))
l10 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS333) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.dem, weights = teamweight, family=binomial(link="logit"))
l11 <- glm(as.factor(STL432x_1rc.number) ~ as.numeric(iUMS333) +
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.ind, weights = teamweight, family=binomial(link="logit"))
l12 <- glm(as.factor(STL432x_1rc.number) ~as.numeric(iUMS333) + 
                                       as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                                     data = cces18.white.rep, weights = teamweight, family=binomial(link="logit"))

stargazer(l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Perceived % Arab",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep","Dem", "Ind", "Rep", "Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are logit regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger support. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces18punishnoncitizenparty.htm")

ces2018punishnoncitizen.white <- dwplot(list(l1, l2, l3), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishnoncitizen.black <- dwplot(list(l4, l5, l6), 
                                  style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                  dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishnoncitizen.latino <- dwplot(list(l7, l8, l9), 
                                   style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                   dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018punishnoncitizen.arab <- dwplot(list(l10, l11, l12), 
                                 style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                                 dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Arabs") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotpunishnoncitizen.2018 <- ggarrange(ces2018punishnoncitizen.white, ces2018punishnoncitizen.black, ces2018punishnoncitizen.latino, ces2018punishnoncitizen.arab, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2018punishnoncitizen.pdf", height = 6, width = 10)
annotate_figure(combinedplotpunishnoncitizen.2018, top = text_grob("White U.S. Voter Support for Awarding Prison Time for Noncitizen Voting, 2018 CES", 
                                                             color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nLogit regression coefficients are given. Larger and positive coefficients indicate stronger support. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

## Restrictions.Felon Enfranchisement

cces17.white.dem$UMS416.number <- as.numeric(cces17.white.dem$UMS416)
cces17.white.ind$UMS416.number <- as.numeric(cces17.white.ind$UMS416)
cces17.white.rep$UMS416.number <- as.numeric(cces17.white.rep$UMS416)

cces18.white.dem$UMS337.number <- as.numeric(cces18.white.dem$UMS337)
cces18.white.ind$UMS337.number <- as.numeric(cces18.white.ind$UMS337)
cces18.white.rep$UMS337.number <- as.numeric(cces18.white.rep$UMS337)

cces17.white.dem$gender2 <- cces17.white.dem$gender
cces17.white.ind$gender2 <- cces17.white.ind$gender
cces17.white.rep$gender2 <- cces17.white.rep$gender

m1 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438x) + 
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces17.white.dem, weights = weights_UMS, Hess = TRUE)
m2 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438x) + 
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces17.white.ind, weights = weights_UMS, Hess = TRUE)
m3 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438x) + 
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces17.white.rep, weights = weights_UMS, Hess = TRUE)
m4 <- polr(as.factor(UMS416.number) ~  as.numeric(iUMS437) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces17.white.dem, weights = weights_UMS, Hess = TRUE)
m5 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS437) + 
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces17.white.ind, weights = weights_UMS, Hess = TRUE)
m6 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS437) +  
            as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
          data = cces17.white.rep, weights = weights_UMS, Hess = TRUE)
m7 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces17.white.dem, weights = weights_UMS, Hess = TRUE)
m8 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces17.white.ind, weights = weights_UMS, Hess = TRUE)
m9 <- polr(as.factor(UMS416.number) ~ as.numeric(iUMS438) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces17.white.rep, weights = weights_UMS, Hess = TRUE)

stargazer(m1, m2, m3, m4, m5, m6, m7, m8, m9, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Immigrant", 
                                             "Perceived % Black",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c(" "),
          column.labels = c("Dem", "Ind", "Repub","Dem", "Ind", "Repub", "Dem", "Ind", "Repub"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger opposition. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces17felonparty.htm")

ces2017felon.white <- dwplot(list(m1, m2, m3), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                               dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017felon.imm <- dwplot(list(m4, m5, m6), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Immigrants") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2017felon.black <- dwplot(list(m7, m8, m9), 
                               style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                               dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS437)' = "Immigrant typification",
                     'as.numeric(iUMS438)' = "Black typification",
                     'as.numeric(iUMS438x)' = "White typification",
                     'as.numeric(ipid7catwns)' = "Republican Party affiliation",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender)Female' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = "bottom",
        legend.justification = c(1, 1),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplot.2017felon <- ggarrange(ces2017felon.white, ces2017felon.imm, ces2017felon.black, ncol=3, nrow=1, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2017felon.pdf", height = 6, width = 12)
annotate_figure(combinedplot.2017felon, top = text_grob("Felon Enfranchisement Opposition Among White U.S. Voters, 2017 CES", 
                                                        color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2017 CES Team Module.\nOrdinal regression coefficients are given. Larger and positive coefficients indicate stronger opposition. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()

n1 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS330) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white.dem, weights = teamweight, Hess = TRUE)
n2 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS330) +
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white.ind, weights = teamweight, Hess = TRUE)
n3 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS330) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white.rep, weights = teamweight, Hess = TRUE)
n4 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS331) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces18.white.dem, weights = teamweight, Hess = TRUE)
n5 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS331) +
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces18.white.ind, weights = teamweight, Hess = TRUE)
n6 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS331) + 
             as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
           data = cces18.white.rep, weights = teamweight, Hess = TRUE)
n7 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS332) +  
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces18.white.dem, weights = teamweight, Hess = TRUE)
n8 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS332) + 
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces18.white.ind, weights = teamweight, Hess = TRUE)
n9 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS332) + 
                                 as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                               data = cces18.white.rep, weights = teamweight, Hess = TRUE)
n10 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS333) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white.dem, weights = teamweight, Hess = TRUE)
n11 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS333) +
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white.ind, weights = teamweight, Hess = TRUE)
n12 <- polr(as.factor(UMS337.number) ~ as.numeric(iUMS333) + 
                                as.numeric(inewsintwdk) + as.numeric(ieduc) + as.numeric(iage) + as.factor(gender2), 
                              data = cces18.white.rep, weights = teamweight, Hess = TRUE)

stargazer(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, style = "apsr",
          title = " ",
          p.auto=FALSE, covariate.labels = c("Perceived % White",
                                             "Perceived % Black",
                                             "Perceived % Latino",
                                             "Perceived % Arab",
                                             "Political interest",
                                             "Education",
                                             "Age",
                                             "Female"),
          model.names = FALSE,
          model.numbers = FALSE,
          dep.var.labels = c("",""),
          column.labels = c("Dem", "Ind", "Rep","Dem", "Ind", "Rep", "Dem", "Ind", "Rep", "Dem", "Ind", "Rep"), align=TRUE,
          column.separate = c(1,1,1,1,1,1,1,1,1,1,1,1),
          star.cutoffs = c(0.05, 0.01, 0.001),
          keep.stat = "n",
          type = "html", notes.align = "l",
          notes = c("Cell entries are ordinal regression coefficients (standard errors in parentheses).", "Larger and positive coefficients indicate stronger opposition. Non-discrete variables are rescaled from 0 to 1."),
          out = "ces18felonparty.htm")

ces2018felon.white <- dwplot(list(n1, n2, n3), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Whites") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018felon.black <- dwplot(list(n4, n5, n6), 
                             style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                             dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Blacks") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018felon.latino <- dwplot(list(n7, n8, n9), 
                              style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                              dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Latinos") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

ces2018felon.arab <- dwplot(list(n10, n11, n12), 
                            style = "dotwhisker", show_intercept = F, dist_args = list(alpha = 0.5, size=1),
                            dot_args = list(aes(shape = model), size = 3)) %>%
  relabel_predictors('as.numeric(iUMS330)' = "White typification",
                     'as.numeric(iUMS331)' = "Black typification",
                     'as.numeric(iUMS332)' = "Latino typification",
                     'as.numeric(iUMS333)' = "Arab typification",
                     'as.numeric(inewsintwdk)' = "Political interest",
                     'as.numeric(ieduc)' = "Education",
                     'as.numeric(iage)' = "Age", 
                     'as.factor(gender2)1' = "Female") +
  theme_bw() + xlab("Coefficient") + ylab("") +
  geom_vline(xintercept = 0, colour = "grey60", linetype = 2) +
  ggtitle("Arabs") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(legend.position = c(0.007, 0.01),
        legend.justification = c(0, 0),
        legend.background = element_rect(colour="grey80", fill = NULL),
        legend.title.align = .5) +
  scale_shape_discrete(name  ="Model",
                       breaks = c("Model 1", "Model 2", "Model 3"),
                       labels = c("Dem", "Ind", "Rep")) +
  scale_colour_grey(start = .4, end = .8,
                    name = "Model",
                    breaks = c("Model 1", "Model 2", "Model 3"),
                    labels = c("Dem", "Ind", "Rep")) +
  guides(shape = guide_legend("Model"), colour = guide_legend("Model"))

combinedplotphoto.2018 <- ggarrange(ces2018photo.white, ces2018photo.black, ces2018photo.latino, ces2018photo.arab, ncol=2, nrow=2, common.legend = TRUE, legend="bottom")

pdf(file = "summary_2018felon.pdf", height = 6, width = 8)
annotate_figure(combinedplotphoto.2018, top = text_grob("Felon Enfranchisement Opposition Among White U.S. Voters, 2018 CES", 
                                                        color = "black", face = "bold", size = 16),
                bottom = text_grob("Source: 2018 CES Team Module.\nOrdinal regression coefficients are given. Larger and positive coefficients indicate stronger opposition. \nNon-discrete variables are rescaled from 0 to 1.",
                                   hjust = 0, x = 0, face = "italic", size = 8))
dev.off()


